<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/vue.min.js"></script>
    <style>
        li {
            border: 1px dashed #999999;
            list-style-type:none;
            margin: 5px;
            line-height: 35px;
            padding-left: 10px;
            font-size: 12px;
            width: 100%;
        }
        li:hover{
            background-color: hotpink;
            transition: all .6s ease;
        }

        .v-enter,
        .v-leave-to{
            opacity: 0;
            transform: translateY(80px);
        }

        .v-enter-active,
        .v-leave-active{
            transition: all .6s ease;
        }
        
        /* 下面的 .v-move 和 .v-leave-active 配合使用， 能够实现列表后续的元素， 渐渐的飘上去 */
        .v-move{
            transition: all .6s ease;
        }
        .v-leave-active{
            position: absolute;
        }
    </style>
</head>
<body>
    <div id="app">
        <div>
            <label>
                Id:
                <input type="text" v-model = "id">
            </label>
            <label>
                Name:
                <input type="text" v-model = "name">
            </label>
            <input type="button" value="添加" @click = "add">
        </div>
        
            <!-- 在实现列表过渡的时候，如果需要过渡的元素，是通过v-for渲染的，不能通过transition包裹，需要使用transitionGroup -->
            <!-- 如果要为v-for 循环创建的元素设置动画，必须为每一个元素设置 :key 属性 -->
            <!-- 给 transition-group 设置 appear 属性，实现页面刚展示出来的时候的入场效果 -->
            <!-- 通过 给 transition-group 设置 tag属性，指定transition-group渲染成什么元素，如果不指定tag属性，默认渲染为span标签 -->
            <transition-group appear tag = "ul">
                <li :key = "item.id" v-for = "(item, i) in list" @click = "del(i)">{{ item.id}}---- {{item.name}}</li>
            </transition-group>
        
    </div>
    
    <script>
        var vm = new Vue({
            el:"#app",
            data:{
                id: '',
                name: '',
                list:[
                    {id:1, name: '赵高'},
                    {id:2, name: "秦桧"},
                    {id:3, name: "严嵩"},
                    {id:4, name: "魏忠贤"},
                    {id:5, name: "罗震林"},
                    {id:6, name: "蒋振东"},
                    {id:7, name: "徐浪"},
                ]
            },
            methods: {
                add() {
                    this.list.push({id: this.id, name: this.name})
                    this.id = this.name = ""
                    
                },
                del(i) {
                    //console.log(i)
                    //splice方法:删除元素，每次删除1个
                    this.list.splice(i,1)
                }
            }
        })
    </script>
</body>
</html>